package edu.gatech.cs2340.group7.wheresmystuffapp.views;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import edu.gatech.cs2340.group7.wheresmystuffapp.R;
import edu.gatech.cs2340.group7.wheresmystuffapp.presenters.DeleteAccountPresenter;

public class DeleteAccountView extends Activity implements View.OnClickListener {
	private String PACKAGE_NAME;
	private DeleteAccountPresenter myPresenter;
	private EditText emailToDelete;
	private Button bCancel;
	private Button bDelete;
	private TextView tvDeleteResult;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_remove_account);
		initialize();
		PACKAGE_NAME = getApplicationContext().getPackageName();
		myPresenter = new DeleteAccountPresenter(this);
	}

	@Override
	public void onClick(View view) {
		// TODO Auto-generated method stub
		switch (view.getId()) {
		case R.id.b_admin_cancel_from_delete:
			Intent intent = new Intent(this, AdminMainMenuView.class);
			intent.setPackage(PACKAGE_NAME);
			startActivity(intent);
			break;
		case R.id.b_admin_delete:
			String username = emailToDelete.getText().toString();
			myPresenter.deleteUser(username);
			break;
		}

	}

	/**
	 * Displays a confirmation message
	 * @param result the message to display
	 */
	public void setDeleteResultText(String result) {
		tvDeleteResult.setText(result);
		tvDeleteResult.setTextColor(Color.RED);
	}
	
	/**
	 * Initializes all the views in the XML layout, and sets listeners for all the buttons
	 */
	private void initialize() {
		emailToDelete = (EditText) findViewById(R.id.et_admin_email_delete);
		bCancel = (Button) findViewById(R.id.b_admin_cancel_from_delete);
		bDelete = (Button) findViewById(R.id.b_admin_delete);
		tvDeleteResult = (TextView) findViewById(R.id.tv_admin_delete_result);

		bCancel.setOnClickListener(this);
		bDelete.setOnClickListener(this);
	}
}
